var _webRoot_Path = "/HyManageSystem";
var modules = [ {
	include : true,
	incfile : _webRoot_Path+'/style/common/reset.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/style/common/button_a.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/style/common/list.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common_dept_worker.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common_cw_subject_funds.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/frameworkutil.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/ymPrompt4/ymPrompt.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/My97DatePicker/WdatePicker.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/ymPrompt4/skin/vista/ymPrompt.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/webtoolkit.scrollabletable.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/webtoolkit.jscrollable.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/jquery.tablesorter.js'
} ];

for ( var i = 0; i < modules.length; i++) {
	if (modules[i].include === true) {
		filename = modules[i].incfile;
		if (jQuery.browser.safari) {
			jQuery.ajax({
				url : filename,
				dataType : 'script',
				async : false,
				cache : true
			});
		} else {
			var fileType = filename.substring(filename.lastIndexOf('.') + 1,
					filename.length).toUpperCase();
			if (fileType == 'JS') {
				IncludeJavaScript(filename);
			} else if (fileType == 'CSS') {
				IncludeCss(filename);
			}
		}
	}
}

/**
 * 导入JS文件到页面
 * 
 * @param jsFile
 */
function IncludeJavaScript(jsFile) {
	var oHead = document.getElementsByTagName('head')[0];
	var oScript = document.createElement('script');
	oScript.type = 'text/javascript';
	oScript.charset = 'utf-8';
	oScript.src = jsFile;
	oHead.appendChild(oScript);
};

/**
 * 导入CSS文件到页面
 * 
 * @param cssFile
 */
function IncludeCss(cssFile) {
	var oHead = document.getElementsByTagName('head')[0];
	var oLink = document.createElement('link');
	oLink.rel = "stylesheet";
	oLink.type = 'text/css';
	oLink.href = cssFile;
	oHead.appendChild(oLink);
};
function changeForSelect(p_select,p_doType,doid){
	var str = "";
	if(p_select==1){
		str="[{id:'"+doid+"'}]";
	}else{
		var checkedBox = $(":checkbox[name='dot_dc_data'][checked]");
		if(checkedBox.length<= 0){
			alert('请选择要修改的记录');return;
		}
		str="[";
		var i=0;
		checkedBox.each(function() {
			str+="{";
			str+="id:'"+$(this).attr("id")+"'";
			str+="}";
			if(i< checkedBox.length-1){
				str+=",";
			}
			i++;
		});
		str+="]";
	}
	var datas = {
			'p_doType':p_doType,
			'p_doFlid':"type",
	        'p_selectList': str
	    };
    if(confirm("您确定执行该记录修改操作吗？")){
    	var url = _rootPath+'/v/user/changeForSelect';
    	postData(url, datas, function(msg){
    		if(msg.infoNo==1){
				alert(msg.infoStr);
				window.location.reload(true);
			}else if(msg.infoNo==-9999){
				alert(msg.infoStr);
				return;
			}else if(msg.infoNo==-1000){
				window.location.href=_webRoot_Path+"/v/system/error";
				return;
			}else{
				alert(msg.infoStr);
			}
        });
	}
}
function addCode(num){
	var datas = {
			 'p_num': 20
       };
	if(confirm("您确定执行该操作吗？")){
		var url = _rootPath+'/v/code/addCode';
		postData(url, datas, function(msg){
			if(msg.infoNo==1){
				alert(msg.infoStr);
				window.location.reload(true);
			}else if(msg.infoNo==-9999){
				alert(msg.infoStr);
				return;
			}else if(msg.infoNo==-1000){
				window.location.href=_webRoot_Path+"/v/system/error";
				return;
			}else{
				alert(msg.infoStr);
			}
		});
	}
}
function searchData(){
    var p_totype = $("#p_totype").val();
    var p_nowtype = $("#p_nowtype").val();
    var p_state = $("#p_state").val();
    var p_startTime = $("#p_startTime").val();
    var p_endTime = $("#p_endTime").val();
    location.href = _rootPath + "/v/user/applyLog?p_state=" + p_state +
    "&p_totype=" +
    p_totype +
    "&p_nowtype=" +
    p_nowtype+"&p_endtime=" + p_endTime+
    "&p_starttime=" +
    p_startTime;
};
function getUserLevel(type){
	if(type == 1){
		return "新手";
	}else if(type == 2){
		return "会员";
	}else if(type == 3){
		return "VIP会员";
	}
}
function saveEntityByApply(){
    var p_apply_remark = $.trim($("#ym-window").find("#p_apply_remark").val());
    var p_user_level = $("#ym-window").find("#p_user_level").val();
    var p_apply_state = $('input:radio[name="p_apply_state"]:checked').val();
    var p_id = $("#ym-window").find("#p_id").val();
    var result = {
            'p_id': p_id,
            'p_apply_remark': p_apply_remark,
            'p_user_level': p_user_level,
            'p_apply_state': p_apply_state
        };
        var url = _rootPath +"/v/user/upApplyEntity";
        postData(url, result, function(msg){
            if (msg.infoNo == 1) {
                alert(msg.infoStr);
                window.location.reload();
            }
            else {
                alert(msg.infoStr);
            }
        });
}
function showApply(id){
    try {
    	if (null == id || id <= 0) {
    	        alert("请选择要操作的数据!");
    	        return false;
    	    }
        var result = {
            'id': id
        };
        var url = _rootPath+"/v/user/getApplyEntity";
        postData(url, result, function(msg){
            if (msg.infoNo == 1) {
                var constObj = eval(msg.myEntity);
                var obj = constObj[0];
                ymPrompt.win({
                    message: $('#showApply').html(),
                    width: 470,
                    height: 300,
                    title: '审核用户申请信息'
                });
                $("#ym-window").find("#bankButton").html('');
                $("#ym-window").find('input:radio[name="p_apply_state"][value=' +
                		obj.state +
                ']').attr('checked', true);
                $("#ym-window").find("#p_id").val(obj.id);
                $("#ym-window").find("#p_apply_remark").val(obj.remark);
                $("#ym-window").find("#p_now_type").val(getUserLevel(obj.nowType));
                $("#ym-window").find("#p_to_type").val(getUserLevel(obj.toType));
                $("#ym-window").find("#p_user_level").val(obj.toType);
                var contentHTML = [];
                var jsonSnsList = eval(msg.mySnsEntity);
                for (var i = 0; i < jsonSnsList.length; i++) {
                	contentHTML.push("<td>"+getSnsType(jsonSnsList[i].p3)+":<a target='_blank' href='"+getSnsUrl(jsonSnsList[i].p3)+jsonSnsList[i].p1+"'>"+jsonSnsList[i].p2+"</a></td>");
                }
                if(jsonSnsList.length>0){
                	$("#ym-window").find("#sns_info").show();
                	$("#ym-window").find("#sns_info").html(contentHTML.join(''));
                }
            }
            else {
                alert(msg.infoStr);
            }
        });
        
    } 
    catch (e) {
        alert(e.message);
        return;
    }
}
function getSnsType(types){
	if(types == '1'){
		return "新浪";
	}else if(types == '2'){
		return "腾讯";
	}
}
function getSnsUrl(types){
	if(types == '1'){
		return "http://weibo.com/u/";
	}else if(types == '2'){
		return "http://t.qq.com/";
	}
}
